# constants.py
# 自然卦序 ==> 八卦
BAGUA = '乾兑离震巽坎艮坤'

FIX_LST = '天泽火雷风水山地'

# 项目卦序//8 ==> 卦宫
BAGUA_ORDERED = '乾震坎巽艮坤离兑'

SX_LST = '猪鼠牛虎兔龙蛇马羊猴鸡狗'

GAN = ["癸", "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬"]
ZHI = ["亥", "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌"]
KONG_WANG = ["戌亥", "子丑", "寅卯", "辰巳", "午未", "申酉"]
LIU_QIN = ['兄弟', '子孙', '妻财', '官鬼', "父母"]
YONG_SHEN = ['用神', '闲神', '仇神', '忌神', '元神']
# YONG_SHEN = ["父母", '兄弟', '子孙', '妻财', '官鬼', '世', '应']
ANIMALS = ["青龙", "朱雀", "勾陈", "腾蛇", "白虎", "玄武"]
YAO_WEI = ["六", "五", "四", "三", "二", "初"]

GUA_NAME_LST = [
    '乾', '夬', '大有', '大壮', '小畜', '需', '大畜', '泰',
    '履', '兑', '睽', '归妹', '中孚', '节', '损', '临',
    '同人', '革', '离', '丰', '家人', '既济', '贲', '明夷',
    '无妄', '随', '噬嗑', '震', '益', '屯', '颐', '复',
    '姤', '大过', '鼎', '恒', '巽', '井', '蛊', '升',
    '讼', '困', '未济', '解', '涣', '坎', '蒙', '师',
    '遁', '咸', '旅', '小过', '渐', '蹇', '艮', '谦',
    '否', '萃', '晋', '豫', '观', '比', '剥', '坤'
]
REMAINDER_SELF = [0, 5, 4, 3, 2, 1, 2, 3]
REMAINDER_OTHER = [3, 2, 1, 0, 5, 4, 5, 0]

# 天干 % 10 ==> six_mode
REMAINDER_TO_SIX_MODE = [0, 1, 1, 2, 2, 3, 4, 5, 5, 0]

# 地支 % 12 ==> zhi_wx
ZHI_TO_WX = [1, 1, 4, 2, 2, 4, 3, 3, 4, 0, 0, 4]
WX = ['金', '水', '木', '火', '土']
WXDiff = ['扶', '生', '克', '耗', '泄']

NATURE_TO_PROJECT_GUA_IDX = (
    0, 45, 7, 44, 25, 46, 34, 43, 37, 56, 36, 63, 38, 17, 35, 42, 55, 20, 48, 21, 26, 19, 33, 22, 28, 15, 29, 8, 27,
    18, 30, 41, 1, 14, 50, 11, 24, 13, 31, 12, 54, 57, 51, 10, 53, 16, 52, 23, 2, 59, 49, 62, 39, 60, 32, 61, 3, 58,
    6, 9, 4, 47, 5, 40
)

PROJECT_TO_NATURE_GUA_IDX = (
    0, 32, 48, 56, 60, 62, 58, 2, 27, 59, 43, 35, 39, 37, 33, 25, 45, 13, 29, 21, 17, 19, 23, 47, 36, 4, 20, 28, 24,
    26, 30, 38, 54, 22, 6, 14, 10, 8, 12, 52, 63, 31, 15, 7, 3, 1, 5, 61, 18, 50, 34, 42, 46, 44, 40, 16, 9, 41, 57,
    49, 53, 55, 51, 11
)

GAN_SHU = ((9, 1), (4,), (6,), (7,), (8,), (5,), (3,), (10, 2))
ZHI_SHU = [(11, 9, 7, 5, 3, 1), (8, 10, 0, 2, 4, 6), (6, 8, 10, 0, 2, 4), (11, 9, 7, 5, 3, 1),
           (4, 6, 8, 10, 0, 2), (1, 11, 9, 7, 5, 3), (3, 1, 11, 9, 7, 5), (10, 0, 2, 4, 6, 8)]
BAGUA_TO_NATURE = {0: 0, 1: 3, 2: 5, 3: 4, 4: 6, 5: 7, 6: 2, 7: 1}

HIDE_SHU = {
    1: [4], 2: [4, 5], 3: [5], 4: [1, 5], 5: [1], 6: [5], 9: [5], 10: [5], 11: [4], 12: [2, 4], 13: [2, 4],
    14: [2, 4], 15: [2], 18: [3], 19: [3], 20: [3], 22: [3], 25: [3], 26: [3], 27: [3], 30: [1, 3], 31: [1],
    33: [3, 4], 34: [3, 4], 35: [3], 36: [1], 37: [1], 38: [1, 3], 39: [1], 41: [4], 43: [4], 45: [4], 46: [4],
    49: [3, 5], 50: [5], 51: [3], 52: [2], 53: [2, 3], 54: [3], 59: [4], 60: [4], 61: [4], 62: [2, 4], 63: [2]
}

GUA_NAME = [
    '乾', '姤', '遁', '否', '观', '剥', '晋', '大有', '震', '豫', '解', '恒', '升', '井', '大过', '随',
    '坎', '节', '屯', '既济', '革', '丰', '明夷', '师', '巽', '小畜', '家人', '益', '无妄', '噬嗑', '颐', '蛊',
    '艮', '贲', '大畜', '损', '睽', '履', '中孚', '渐', '坤', '复', '临', '泰', '大壮', '夬', '需', '比',
    '离', '旅', '鼎', '未济', '蒙', '涣', '讼', '同人', '兑', '困', '萃', '咸', '蹇', '谦', '小过', '归妹'
]

GUA_NAMES = [
    '乾为天', '天风姤', '天山遁', '天地否', '风地观', '山地剥', '火地晋', '火天大有',
    '震为雷', '雷地豫', '雷水解', '雷风恒', '地风升', '水风井', '泽风大过', '泽雷随',
    '坎为水', '水泽节', '水雷屯', '水火既济', '泽火革', '雷火丰', '地火明夷', '地水师',
    '巽为风', '风天小畜', '风火家人', '风雷益', '天雷无妄', '火雷噬嗑', '山雷颐', '山风蛊',
    '艮为山', '山火贲', '山天大畜', '山泽损', '火泽睽', '天泽履', '风泽中孚', '风山渐',
    '坤为地', '地雷复', '地泽临', '地天泰', '雷天大壮', '泽天夬', '水天需', '水地比',
    '离为火', '火山旅', '火风鼎', '火水未济', '山水蒙', '风水涣', '天水讼', '天火同人',
    '兑为泽', '泽水困', '泽地萃', '泽山咸', '水山蹇', '地山谦', '雷山小过', '雷泽归妹', '空白']

# REMINDER_TO_WX[context['gua'] // 8]
REMINDER_TO_WX = [0, 2, 1, 2, 4, 4, 3, 0]
# REMINDER_TO_WX = [4, 3, 1, 3, 0, 0, 2, 4]
# WX_ForGuaPalace = '土水火木金'

# 行数代表五行，(0土 1水 2卦宫属火 3木 4金乾兑宫)
LIU_QIN_NUM_60 = [
    [24, 25, 2, 39, 40, 5, 54, 55, 8, 21, 22, 11],
    [12, 13, 50, 27, 28, 53, 42, 43, 56, 9, 10, 59],
    [0, 1, 38, 15, 16, 41, 30, 31, 44, 57, 58, 47],
    [48, 49, 26, 3, 4, 29, 18, 19, 32, 45, 46, 35],
    [36, 37, 14, 51, 52, 17, 6, 7, 20, 33, 34, 23],
]

# %12 的序数依然对应地支，//12 的序数对应六亲
FAMILY = [
    '父母亥水', '父母子水', '父母丑土', '父母寅木', '父母卯木', '父母辰土', '父母巳火', '父母午火', '父母未土',
    '父母申金', '父母酉金', '父母戌土', '兄弟亥水', '兄弟子水', '兄弟丑土', '兄弟寅木', '兄弟卯木', '兄弟辰土',
    '兄弟巳火', '兄弟午火', '兄弟未土', '兄弟申金', '兄弟酉金', '兄弟戌土', '子孙亥水', '子孙子水', '子孙丑土',
    '子孙寅木', '子孙卯木', '子孙辰土', '子孙巳火', '子孙午火', '子孙未土', '子孙申金', '子孙酉金', '子孙戌土',
    '妻财亥水', '妻财子水', '妻财丑土', '妻财寅木', '妻财卯木', '妻财辰土', '妻财巳火', '妻财午火', '妻财未土',
    '妻财申金', '妻财酉金', '妻财戌土', '官鬼亥水', '官鬼子水', '官鬼丑土', '官鬼寅木', '官鬼卯木', '官鬼辰土',
    '官鬼巳火', '官鬼午火', '官鬼未土', '官鬼申金', '官鬼酉金', '官鬼戌土', '官鬼亥水']

ALIASES = {
    '上爻': '六爻',
    '宅爻': '二爻',
    '一爻': '初爻',
    '六': '六爻',
    '五': '五爻',
    '四': '四爻',
    '三': '三爻',
    '二': '二爻',
    '初': '初爻',
}  # 别名映射（相同索引不同名称）

BASIC_WORD_MAPPING = {
    '六爻': 0, '五爻': 1, '四爻': 2, '三爻': 3, '二爻': 4, '初爻': 5, '一爻': 5,
    '外卦': 6, '内卦': 7, '主卦': 8,  # 固定层
    '阳': 9, '阴': 10, '安静': 11, '发动': 12, '变卦': 13, '伏藏': 14,
    '金': 15, '水': 16, '木': 17, '火': 18, '土': 19, '亥': 20, '子': 21, '丑': 22,  '寅': 23,
    '卯': 24, '辰': 25, '巳': 26, '午': 27, '未': 28, '申': 29, '酉': 30, '戌': 31,  '动': 32,
    '回头扶': 33, '回头生': 34, '回头克': 35, '回头耗': 36, '回头泄': 37,  # wx_alter
    '动爻扶': 38, '动爻生': 39, '动爻克': 40, '动爻耗': 41, '动爻泄': 42,  # wx_vary
    '化差0': 43, '化和0': 55, '动差0': 67, '动和0': 79,
    '化差1': 44, '化和1': 56, '动差1': 68, '动和1': 80,
    '化差2': 45, '化和2': 57, '动差2': 69, '动和2': 81,
    '化差3': 46, '化和3': 58, '动差3': 70, '动和3': 82,
    '化差4': 47, '化和4': 59, '动差4': 71, '动和4': 83,
    '化差5': 48, '化和5': 60, '动差5': 72, '动和5': 84,
    '化差6': 49, '化和6': 61, '动差6': 73, '动和6': 85,
    '化差7': 50, '化和7': 62, '动差7': 74, '动和7': 86,
    '化差8': 51, '化和8': 63, '动差8': 75, '动和8': 87,
    '化差9': 52, '化和9': 64, '动差9': 76, '动和9': 88,
    '化差10': 53, '化和10': 65, '动差10': 77, '动和10': 89,
    '化差11': 54, '化和11': 66, '动差11': 78, '动和11': 90
    # zhi_alter，            zhi_vary
}

FLEXIBLE_WORD_MAPPING = {
    "六爻": "上爻",
    "月生扶": "(月生|月扶)",
    "日生扶": "(日生|日扶)",
    "月不生扶": "(月克|月泄|月耗)",
    "日不生扶": "(日克|日泄|日耗)",
    "暗动": "安静&日冲",
    "化进": "回头扶&(化差1|化差3)",
    "化退": "回头扶&(化差11|化差9)",
    "化合": "化和3",
    "反吟": "化差6",
    "伏吟": "化差0",
    "动爻冲":"动差6",
    "动爻合":"动和3",
    "月破": "月差6", "月合": "月和3", "月建": "月差0", "次月": "月差1",
    "日冲": "日差6", "日合": "日和3", "日害": "日和9", "日辰": "日差0", "明日": "日差1", "昨日": "日差11",
    "世爻": f"主卦&世",
    "应爻": f"主卦&应",
    "间爻": f"主卦&间",
}
LAYER_MAP = {
    (0, 2): ('yinyang', '阴阳'),
    (2, 6): ('block', '卦象块'),
    (6, 11): ('wx', '五行'),
    (11, 23): ('zhi', '地支'),
    (23, 24): ('vary', '动爻标记'),
    (24, 29): ('wx_alter', '回头生克'),
    (29, 34): ('wx_vary', '动爻作用'),
    (34, 58): ('zhi_alter', '变爻对动爻的地支差/和'),
    (58, 82): ('zhi_vary', '动爻与其他爻的地支差/和'),
}

if __name__ == '__main__':
    # BAGUA_TO_NATURE 的作用
    for i in range(8):
        gua_idx = i * 8
        print('卦名&序数:',GUA_NAMES[gua_idx], gua_idx)
        print('卦宫:',BAGUA[BAGUA_TO_NATURE[i]])

    # GAN_SHU
    for li in GAN_SHU:
        print([li[0]] * 3 + [li[-1]] * 3)
    gan_shu = [[li[0]] * 3 + [li[-1]] * 3 for li in GAN_SHU]
    print(gan_shu)
